package com.example.hrv.Algorithm;


/**
 * Created by niesh on 2017/5/17.
 */

public class EcgJinClient {
    static {
        System.loadLibrary("EcgAlgorithm");
    }

    public static final int  kLoPass     = 10000;
    public static final int  kHiPass     = 10001;
    public static final int  kBandPass   = 10002;
    public static final int  kBandStop   = 10003;
    public static final int  kLoShelf    = 10004;
    public static final int  kHiShelf    = 10005; // high order EQ
    public static final int  kParametric = 10006;  // high order EQ

    /**
     * @param sampleData 采样数据
     * @param sampleLen  采样数据长度
     * @param sampleRate 采用率
     * @param sensorType 前端设备类型  参考 SensorType
     * @return 返回 计算得到的心率值
     */
    public static native int CalculateHeartRate(long[] sampleData, int sampleLen, int sampleRate);

    /**
     * @param sampleData 采样数据
     * @param sampleLen  采样数据长度
     * @param sampleRate 采用率
     * @param sensorType 前端设备类型  参考 SensorType
     * @param hrvResult  HRV分析结果
     * @return 1 计算ok 0 失败
     */
    static public native ResultOfHRV CalculateHRVResult(long[] sampleData, int sampleLen, int sampleRate, ResultOfHRV hrvResult);

    /**
     * @param sampleData 采样数据
     * @param sampleLen  采样数据长度
     * @return
     */
    static public native void CalculateSCL(float[] sampleData, int sampleLen);

    /**
     * @param sampleData
     * @param sampleLen
     * @return
     */
    static public native int FilterData(float[] sampleData, int sampleLen);

    /**
     * @param fs          ²ÉÑùÂÊ
     * @param type        ÂË²¨ÀàÐÍ
     *                    µÍÍ¨     = 10000,
     *                    ¸ßÍ¨     = 10001,
     *                    ´øÍ¨   = 10002,
     *                    ´ø×è   = 10003,
     * @param filerorder  ÂË²¨½ÓÊý
     * @param low_cutoff  µÍÍ¨ÆµÂÊ
     * @param high_cutoff ¸ßÍ¨ÆµÂÊ
     * @return
     */
    static public native int InitButtFiler(int fs, int type, int filerorder, float low_cutoff, float high_cutoff);

    /**
     *
     * @param sampleData 采样数据 计算成功后返回RR间期数据
     * @param sampleLen 采样数据长度
     * @return 返回计算得到的RR间期长度
     */
    static public native int CaculateRRInterval(int[] sampleData, int sampleLen);
//    static public native int CaculateRRInterval(float[] sampleData,int sampleLen);

    /**
     * @param rrInterval    RR间期数据
     * @param rrIntervalLen RR间期长度
     * @param sampleRate    采样率
     * @param hrvResult     HRV分析结果
     * @return 1 计算ok 0 失败
     */
    static public native ResultOfHRV CalculateHRVResultByRRData(int[] rrInterval, int rrIntervalLen, int sampleRate, ResultOfHRV hrvResult);

    public static int calculateHeartRate(long[] sampleData, int sampleLen, int sampleRate) {
        return CalculateHeartRate(sampleData, sampleLen, sampleRate);
    }

    public static ResultOfHRV calculateHRVResult(long[] sampleData, int sampleLen, int sampleRate, ResultOfHRV hrvResult) {
        return CalculateHRVResult(sampleData, sampleLen, sampleRate, hrvResult);
    }

    public static float[] calculateSCL(float[] sampleData, int sampleLen) {
        CalculateSCL(sampleData, sampleLen);
        return sampleData;
    }

    public static int filterData(float[] sampleData, int sampleLen) {
        return FilterData(sampleData, sampleLen);
    }

    public static int initButtFiler(int fs, int type, int filerorder, float low_cutoff, float high_cutoff) {
        return InitButtFiler(fs, type, filerorder, low_cutoff, high_cutoff);
    }
}
